package cn.tedu.order.tx;

import com.zaxxer.hikari.HikariDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * 数据源配置
 * @author Amos
 * @date 2022/4/24
 */

@Configuration
public class DsConf {
    // 新建原始数据源对象
    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource dataSource() {
        return new HikariDataSource();
    }

    // 新建数据源的代理对象
    @Primary // 首选对象
    @Bean
    public DataSource dataSourceProxy(DataSource ds) {
        return new DataSourceProxy(ds);
    }
}
